/* eslint-disable */
import { Reader, Writer } from 'protobufjs/minimal'
import { Any } from '../../../../google/protobuf/any'

export const protobufPackage = 'ibc.core.client.v1'

/** MsgCreateClient defines a message to create an IBC client */
export interface MsgCreateClient {
  /** light client state */
  clientState: Any | undefined
  /**
   * consensus state associated with the client that corresponds to a given
   * height.
   */
  consensusState: Any | undefined
  /** signer address */
  signer: string
}

/** MsgCreateClientResponse defines the Msg/CreateClient response type. */
export interface MsgCreateClientResponse {}

/**
 * MsgUpdateClient defines an sdk.Msg to update a IBC client state using
 * the given header.
 */
export interface MsgUpdateClient {
  /** client unique identifier */
  clientId: string
  /** header to update the light client */
  header: Any | undefined
  /** signer address */
  signer: string
}

/** MsgUpdateClientResponse defines the Msg/UpdateClient response type. */
export interface MsgUpdateClientResponse {}

/** MsgUpgradeClient defines an sdk.Msg to upgrade an IBC client to a new client state */
export interface MsgUpgradeClient {
  /** client unique identifier */
  clientId: string
  /** upgraded client state */
  clientState: Any | undefined
  /** upgraded consensus state, only contains enough information to serve as a basis of trust in update logic */
  consensusState: Any | undefined
  /** proof that old chain committed to new client */
  proofUpgradeClient: Uint8Array
  /** proof that old chain committed to new consensus state */
  proofUpgradeConsensusState: Uint8Array
  /** signer address */
  signer: string
}

/** MsgUpgradeClientResponse defines the Msg/UpgradeClient response type. */
export interface MsgUpgradeClientResponse {}

/**
 * MsgSubmitMisbehaviour defines an sdk.Msg type that submits Evidence for
 * light client misbehaviour.
 */
export interface MsgSubmitMisbehaviour {
  /** client unique identifier */
  clientId: string
  /** misbehaviour used for freezing the light client */
  misbehaviour: Any | undefined
  /** signer address */
  signer: string
}

/** MsgSubmitMisbehaviourResponse defines the Msg/SubmitMisbehaviour response type. */
export interface MsgSubmitMisbehaviourResponse {}

const baseMsgCreateClient: object = { signer: '' }

export const MsgCreateClient = {
  encode(message: MsgCreateClient, writer: Writer = Writer.create()): Writer {
    if (message.clientState !== undefined) {
      Any.encode(message.clientState, writer.uint32(10).fork()).ldelim()
    }
    if (message.consensusState !== undefined) {
      Any.encode(message.consensusState, writer.uint32(18).fork()).ldelim()
    }
    if (message.signer !== '') {
      writer.uint32(26).string(message.signer)
    }
    return writer
  },

  decode(input: Reader | Uint8Array, length?: number): MsgCreateClient {
    const reader = input instanceof Uint8Array ? new Reader(input) : input
    let end = length === undefined ? reader.len : reader.pos + length
    const message = { ...baseMsgCreateClient } as MsgCreateClient
    while (reader.pos < end) {
      const tag = reader.uint32()
      switch (tag >>> 3) {
        case 1:
          message.clientState = Any.decode(reader, reader.uint32())
          break
        case 2:
          message.consensusState = Any.decode(reader, reader.uint32())
          break
        case 3:
          message.signer = reader.string()
          break
        default:
          reader.skipType(tag & 7)
          break
      }
    }
    return message
  },

  fromJSON(object: any): MsgCreateClient {
    const message = { ...baseMsgCreateClient } as MsgCreateClient
    if (object.clientState !== undefined && object.clientState !== null) {
      message.clientState = Any.fromJSON(object.clientState)
    } else {
      message.clientState = undefined
    }
    if (object.consensusState !== undefined && object.consensusState !== null) {
      message.consensusState = Any.fromJSON(object.consensusState)
    } else {
      message.consensusState = undefined
    }
    if (object.signer !== undefined && object.signer !== null) {
      message.signer = String(object.signer)
    } else {
      message.signer = ''
    }
    return message
  },

  toJSON(message: MsgCreateClient): unknown {
    const obj: any = {}
    message.clientState !== undefined &&
      (obj.clientState = message.clientState
        ? Any.toJSON(message.clientState)
        : undefined)
    message.consensusState !== undefined &&
      (obj.consensusState = message.consensusState
        ? Any.toJSON(message.consensusState)
        : undefined)
    message.signer !== undefined && (obj.signer = message.signer)
    return obj
  },

  fromPartial(object: DeepPartial<MsgCreateClient>): MsgCreateClient {
    const message = { ...baseMsgCreateClient } as MsgCreateClient
    if (object.clientState !== undefined && object.clientState !== null) {
      message.clientState = Any.fromPartial(object.clientState)
    } else {
      message.clientState = undefined
    }
    if (object.consensusState !== undefined && object.consensusState !== null) {
      message.consensusState = Any.fromPartial(object.consensusState)
    } else {
      message.consensusState = undefined
    }
    if (object.signer !== undefined && object.signer !== null) {
      message.signer = object.signer
    } else {
      message.signer = ''
    }
    return message
  }
}

const baseMsgCreateClientResponse: object = {}

export const MsgCreateClientResponse = {
  encode(_: MsgCreateClientResponse, writer: Writer = Writer.create()): Writer {
    return writer
  },

  decode(input: Reader | Uint8Array, length?: number): MsgCreateClientResponse {
    const reader = input instanceof Uint8Array ? new Reader(input) : input
    let end = length === undefined ? reader.len : reader.pos + length
    const message = {
      ...baseMsgCreateClientResponse
    } as MsgCreateClientResponse
    while (reader.pos < end) {
      const tag = reader.uint32()
      switch (tag >>> 3) {
        default:
          reader.skipType(tag & 7)
          break
      }
    }
    return message
  },

  fromJSON(_: any): MsgCreateClientResponse {
    const message = {
      ...baseMsgCreateClientResponse
    } as MsgCreateClientResponse
    return message
  },

  toJSON(_: MsgCreateClientResponse): unknown {
    const obj: any = {}
    return obj
  },

  fromPartial(
    _: DeepPartial<MsgCreateClientResponse>
  ): MsgCreateClientResponse {
    const message = {
      ...baseMsgCreateClientResponse
    } as MsgCreateClientResponse
    return message
  }
}

const baseMsgUpdateClient: object = { clientId: '', signer: '' }

export const MsgUpdateClient = {
  encode(message: MsgUpdateClient, writer: Writer = Writer.create()): Writer {
    if (message.clientId !== '') {
      writer.uint32(10).string(message.clientId)
    }
    if (message.header !== undefined) {
      Any.encode(message.header, writer.uint32(18).fork()).ldelim()
    }
    if (message.signer !== '') {
      writer.uint32(26).string(message.signer)
    }
    return writer
  },

  decode(input: Reader | Uint8Array, length?: number): MsgUpdateClient {
    const reader = input instanceof Uint8Array ? new Reader(input) : input
    let end = length === undefined ? reader.len : reader.pos + length
    const message = { ...baseMsgUpdateClient } as MsgUpdateClient
    while (reader.pos < end) {
      const tag = reader.uint32()
      switch (tag >>> 3) {
        case 1:
          message.clientId = reader.string()
          break
        case 2:
          message.header = Any.decode(reader, reader.uint32())
          break
        case 3:
          message.signer = reader.string()
          break
        default:
          reader.skipType(tag & 7)
          break
      }
    }
    return message
  },

  fromJSON(object: any): MsgUpdateClient {
    const message = { ...baseMsgUpdateClient } as MsgUpdateClient
    if (object.clientId !== undefined && object.clientId !== null) {
      message.clientId = String(object.clientId)
    } else {
      message.clientId = ''
    }
    if (object.header !== undefined && object.header !== null) {
      message.header = Any.fromJSON(object.header)
    } else {
      message.header = undefined
    }
    if (object.signer !== undefined && object.signer !== null) {
      message.signer = String(object.signer)
    } else {
      message.signer = ''
    }
    return message
  },

  toJSON(message: MsgUpdateClient): unknown {
    const obj: any = {}
    message.clientId !== undefined && (obj.clientId = message.clientId)
    message.header !== undefined &&
      (obj.header = message.header ? Any.toJSON(message.header) : undefined)
    message.signer !== undefined && (obj.signer = message.signer)
    return obj
  },

  fromPartial(object: DeepPartial<MsgUpdateClient>): MsgUpdateClient {
    const message = { ...baseMsgUpdateClient } as MsgUpdateClient
    if (object.clientId !== undefined && object.clientId !== null) {
      message.clientId = object.clientId
    } else {
      message.clientId = ''
    }
    if (object.header !== undefined && object.header !== null) {
      message.header = Any.fromPartial(object.header)
    } else {
      message.header = undefined
    }
    if (object.signer !== undefined && object.signer !== null) {
      message.signer = object.signer
    } else {
      message.signer = ''
    }
    return message
  }
}

const baseMsgUpdateClientResponse: object = {}

export const MsgUpdateClientResponse = {
  encode(_: MsgUpdateClientResponse, writer: Writer = Writer.create()): Writer {
    return writer
  },

  decode(input: Reader | Uint8Array, length?: number): MsgUpdateClientResponse {
    const reader = input instanceof Uint8Array ? new Reader(input) : input
    let end = length === undefined ? reader.len : reader.pos + length
    const message = {
      ...baseMsgUpdateClientResponse
    } as MsgUpdateClientResponse
    while (reader.pos < end) {
      const tag = reader.uint32()
      switch (tag >>> 3) {
        default:
          reader.skipType(tag & 7)
          break
      }
    }
    return message
  },

  fromJSON(_: any): MsgUpdateClientResponse {
    const message = {
      ...baseMsgUpdateClientResponse
    } as MsgUpdateClientResponse
    return message
  },

  toJSON(_: MsgUpdateClientResponse): unknown {
    const obj: any = {}
    return obj
  },

  fromPartial(
    _: DeepPartial<MsgUpdateClientResponse>
  ): MsgUpdateClientResponse {
    const message = {
      ...baseMsgUpdateClientResponse
    } as MsgUpdateClientResponse
    return message
  }
}

const baseMsgUpgradeClient: object = { clientId: '', signer: '' }

export const MsgUpgradeClient = {
  encode(message: MsgUpgradeClient, writer: Writer = Writer.create()): Writer {
    if (message.clientId !== '') {
      writer.uint32(10).string(message.clientId)
    }
    if (message.clientState !== undefined) {
      Any.encode(message.clientState, writer.uint32(18).fork()).ldelim()
    }
    if (message.consensusState !== undefined) {
      Any.encode(message.consensusState, writer.uint32(26).fork()).ldelim()
    }
    if (message.proofUpgradeClient.length !== 0) {
      writer.uint32(34).bytes(message.proofUpgradeClient)
    }
    if (message.proofUpgradeConsensusState.length !== 0) {
      writer.uint32(42).bytes(message.proofUpgradeConsensusState)
    }
    if (message.signer !== '') {
      writer.uint32(50).string(message.signer)
    }
    return writer
  },

  decode(input: Reader | Uint8Array, length?: number): MsgUpgradeClient {
    const reader = input instanceof Uint8Array ? new Reader(input) : input
    let end = length === undefined ? reader.len : reader.pos + length
    const message = { ...baseMsgUpgradeClient } as MsgUpgradeClient
    while (reader.pos < end) {
      const tag = reader.uint32()
      switch (tag >>> 3) {
        case 1:
          message.clientId = reader.string()
          break
        case 2:
          message.clientState = Any.decode(reader, reader.uint32())
          break
        case 3:
          message.consensusState = Any.decode(reader, reader.uint32())
          break
        case 4:
          message.proofUpgradeClient = reader.bytes()
          break
        case 5:
          message.proofUpgradeConsensusState = reader.bytes()
          break
        case 6:
          message.signer = reader.string()
          break
        default:
          reader.skipType(tag & 7)
          break
      }
    }
    return message
  },

  fromJSON(object: any): MsgUpgradeClient {
    const message = { ...baseMsgUpgradeClient } as MsgUpgradeClient
    if (object.clientId !== undefined && object.clientId !== null) {
      message.clientId = String(object.clientId)
    } else {
      message.clientId = ''
    }
    if (object.clientState !== undefined && object.clientState !== null) {
      message.clientState = Any.fromJSON(object.clientState)
    } else {
      message.clientState = undefined
    }
    if (object.consensusState !== undefined && object.consensusState !== null) {
      message.consensusState = Any.fromJSON(object.consensusState)
    } else {
      message.consensusState = undefined
    }
    if (
      object.proofUpgradeClient !== undefined &&
      object.proofUpgradeClient !== null
    ) {
      message.proofUpgradeClient = bytesFromBase64(object.proofUpgradeClient)
    }
    if (
      object.proofUpgradeConsensusState !== undefined &&
      object.proofUpgradeConsensusState !== null
    ) {
      message.proofUpgradeConsensusState = bytesFromBase64(
        object.proofUpgradeConsensusState
      )
    }
    if (object.signer !== undefined && object.signer !== null) {
      message.signer = String(object.signer)
    } else {
      message.signer = ''
    }
    return message
  },

  toJSON(message: MsgUpgradeClient): unknown {
    const obj: any = {}
    message.clientId !== undefined && (obj.clientId = message.clientId)
    message.clientState !== undefined &&
      (obj.clientState = message.clientState
        ? Any.toJSON(message.clientState)
        : undefined)
    message.consensusState !== undefined &&
      (obj.consensusState = message.consensusState
        ? Any.toJSON(message.consensusState)
        : undefined)
    message.proofUpgradeClient !== undefined &&
      (obj.proofUpgradeClient = base64FromBytes(
        message.proofUpgradeClient !== undefined
          ? message.proofUpgradeClient
          : new Uint8Array()
      ))
    message.proofUpgradeConsensusState !== undefined &&
      (obj.proofUpgradeConsensusState = base64FromBytes(
        message.proofUpgradeConsensusState !== undefined
          ? message.proofUpgradeConsensusState
          : new Uint8Array()
      ))
    message.signer !== undefined && (obj.signer = message.signer)
    return obj
  },

  fromPartial(object: DeepPartial<MsgUpgradeClient>): MsgUpgradeClient {
    const message = { ...baseMsgUpgradeClient } as MsgUpgradeClient
    if (object.clientId !== undefined && object.clientId !== null) {
      message.clientId = object.clientId
    } else {
      message.clientId = ''
    }
    if (object.clientState !== undefined && object.clientState !== null) {
      message.clientState = Any.fromPartial(object.clientState)
    } else {
      message.clientState = undefined
    }
    if (object.consensusState !== undefined && object.consensusState !== null) {
      message.consensusState = Any.fromPartial(object.consensusState)
    } else {
      message.consensusState = undefined
    }
    if (
      object.proofUpgradeClient !== undefined &&
      object.proofUpgradeClient !== null
    ) {
      message.proofUpgradeClient = object.proofUpgradeClient
    } else {
      message.proofUpgradeClient = new Uint8Array()
    }
    if (
      object.proofUpgradeConsensusState !== undefined &&
      object.proofUpgradeConsensusState !== null
    ) {
      message.proofUpgradeConsensusState = object.proofUpgradeConsensusState
    } else {
      message.proofUpgradeConsensusState = new Uint8Array()
    }
    if (object.signer !== undefined && object.signer !== null) {
      message.signer = object.signer
    } else {
      message.signer = ''
    }
    return message
  }
}

const baseMsgUpgradeClientResponse: object = {}

export const MsgUpgradeClientResponse = {
  encode(
    _: MsgUpgradeClientResponse,
    writer: Writer = Writer.create()
  ): Writer {
    return writer
  },

  decode(
    input: Reader | Uint8Array,
    length?: number
  ): MsgUpgradeClientResponse {
    const reader = input instanceof Uint8Array ? new Reader(input) : input
    let end = length === undefined ? reader.len : reader.pos + length
    const message = {
      ...baseMsgUpgradeClientResponse
    } as MsgUpgradeClientResponse
    while (reader.pos < end) {
      const tag = reader.uint32()
      switch (tag >>> 3) {
        default:
          reader.skipType(tag & 7)
          break
      }
    }
    return message
  },

  fromJSON(_: any): MsgUpgradeClientResponse {
    const message = {
      ...baseMsgUpgradeClientResponse
    } as MsgUpgradeClientResponse
    return message
  },

  toJSON(_: MsgUpgradeClientResponse): unknown {
    const obj: any = {}
    return obj
  },

  fromPartial(
    _: DeepPartial<MsgUpgradeClientResponse>
  ): MsgUpgradeClientResponse {
    const message = {
      ...baseMsgUpgradeClientResponse
    } as MsgUpgradeClientResponse
    return message
  }
}

const baseMsgSubmitMisbehaviour: object = { clientId: '', signer: '' }

export const MsgSubmitMisbehaviour = {
  encode(
    message: MsgSubmitMisbehaviour,
    writer: Writer = Writer.create()
  ): Writer {
    if (message.clientId !== '') {
      writer.uint32(10).string(message.clientId)
    }
    if (message.misbehaviour !== undefined) {
      Any.encode(message.misbehaviour, writer.uint32(18).fork()).ldelim()
    }
    if (message.signer !== '') {
      writer.uint32(26).string(message.signer)
    }
    return writer
  },

  decode(input: Reader | Uint8Array, length?: number): MsgSubmitMisbehaviour {
    const reader = input instanceof Uint8Array ? new Reader(input) : input
    let end = length === undefined ? reader.len : reader.pos + length
    const message = { ...baseMsgSubmitMisbehaviour } as MsgSubmitMisbehaviour
    while (reader.pos < end) {
      const tag = reader.uint32()
      switch (tag >>> 3) {
        case 1:
          message.clientId = reader.string()
          break
        case 2:
          message.misbehaviour = Any.decode(reader, reader.uint32())
          break
        case 3:
          message.signer = reader.string()
          break
        default:
          reader.skipType(tag & 7)
          break
      }
    }
    return message
  },

  fromJSON(object: any): MsgSubmitMisbehaviour {
    const message = { ...baseMsgSubmitMisbehaviour } as MsgSubmitMisbehaviour
    if (object.clientId !== undefined && object.clientId !== null) {
      message.clientId = String(object.clientId)
    } else {
      message.clientId = ''
    }
    if (object.misbehaviour !== undefined && object.misbehaviour !== null) {
      message.misbehaviour = Any.fromJSON(object.misbehaviour)
    } else {
      message.misbehaviour = undefined
    }
    if (object.signer !== undefined && object.signer !== null) {
      message.signer = String(object.signer)
    } else {
      message.signer = ''
    }
    return message
  },

  toJSON(message: MsgSubmitMisbehaviour): unknown {
    const obj: any = {}
    message.clientId !== undefined && (obj.clientId = message.clientId)
    message.misbehaviour !== undefined &&
      (obj.misbehaviour = message.misbehaviour
        ? Any.toJSON(message.misbehaviour)
        : undefined)
    message.signer !== undefined && (obj.signer = message.signer)
    return obj
  },

  fromPartial(
    object: DeepPartial<MsgSubmitMisbehaviour>
  ): MsgSubmitMisbehaviour {
    const message = { ...baseMsgSubmitMisbehaviour } as MsgSubmitMisbehaviour
    if (object.clientId !== undefined && object.clientId !== null) {
      message.clientId = object.clientId
    } else {
      message.clientId = ''
    }
    if (object.misbehaviour !== undefined && object.misbehaviour !== null) {
      message.misbehaviour = Any.fromPartial(object.misbehaviour)
    } else {
      message.misbehaviour = undefined
    }
    if (object.signer !== undefined && object.signer !== null) {
      message.signer = object.signer
    } else {
      message.signer = ''
    }
    return message
  }
}

const baseMsgSubmitMisbehaviourResponse: object = {}

export const MsgSubmitMisbehaviourResponse = {
  encode(
    _: MsgSubmitMisbehaviourResponse,
    writer: Writer = Writer.create()
  ): Writer {
    return writer
  },

  decode(
    input: Reader | Uint8Array,
    length?: number
  ): MsgSubmitMisbehaviourResponse {
    const reader = input instanceof Uint8Array ? new Reader(input) : input
    let end = length === undefined ? reader.len : reader.pos + length
    const message = {
      ...baseMsgSubmitMisbehaviourResponse
    } as MsgSubmitMisbehaviourResponse
    while (reader.pos < end) {
      const tag = reader.uint32()
      switch (tag >>> 3) {
        default:
          reader.skipType(tag & 7)
          break
      }
    }
    return message
  },

  fromJSON(_: any): MsgSubmitMisbehaviourResponse {
    const message = {
      ...baseMsgSubmitMisbehaviourResponse
    } as MsgSubmitMisbehaviourResponse
    return message
  },

  toJSON(_: MsgSubmitMisbehaviourResponse): unknown {
    const obj: any = {}
    return obj
  },

  fromPartial(
    _: DeepPartial<MsgSubmitMisbehaviourResponse>
  ): MsgSubmitMisbehaviourResponse {
    const message = {
      ...baseMsgSubmitMisbehaviourResponse
    } as MsgSubmitMisbehaviourResponse
    return message
  }
}

/** Msg defines the ibc/client Msg service. */
export interface Msg {
  /** CreateClient defines a rpc handler method for MsgCreateClient. */
  CreateClient(request: MsgCreateClient): Promise<MsgCreateClientResponse>
  /** UpdateClient defines a rpc handler method for MsgUpdateClient. */
  UpdateClient(request: MsgUpdateClient): Promise<MsgUpdateClientResponse>
  /** UpgradeClient defines a rpc handler method for MsgUpgradeClient. */
  UpgradeClient(request: MsgUpgradeClient): Promise<MsgUpgradeClientResponse>
  /** SubmitMisbehaviour defines a rpc handler method for MsgSubmitMisbehaviour. */
  SubmitMisbehaviour(
    request: MsgSubmitMisbehaviour
  ): Promise<MsgSubmitMisbehaviourResponse>
}

export class MsgClientImpl implements Msg {
  private readonly rpc: Rpc
  constructor(rpc: Rpc) {
    this.rpc = rpc
  }
  CreateClient(request: MsgCreateClient): Promise<MsgCreateClientResponse> {
    const data = MsgCreateClient.encode(request).finish()
    const promise = this.rpc.request(
      'ibc.core.client.v1.Msg',
      'CreateClient',
      data
    )
    return promise.then((data) =>
      MsgCreateClientResponse.decode(new Reader(data))
    )
  }

  UpdateClient(request: MsgUpdateClient): Promise<MsgUpdateClientResponse> {
    const data = MsgUpdateClient.encode(request).finish()
    const promise = this.rpc.request(
      'ibc.core.client.v1.Msg',
      'UpdateClient',
      data
    )
    return promise.then((data) =>
      MsgUpdateClientResponse.decode(new Reader(data))
    )
  }

  UpgradeClient(request: MsgUpgradeClient): Promise<MsgUpgradeClientResponse> {
    const data = MsgUpgradeClient.encode(request).finish()
    const promise = this.rpc.request(
      'ibc.core.client.v1.Msg',
      'UpgradeClient',
      data
    )
    return promise.then((data) =>
      MsgUpgradeClientResponse.decode(new Reader(data))
    )
  }

  SubmitMisbehaviour(
    request: MsgSubmitMisbehaviour
  ): Promise<MsgSubmitMisbehaviourResponse> {
    const data = MsgSubmitMisbehaviour.encode(request).finish()
    const promise = this.rpc.request(
      'ibc.core.client.v1.Msg',
      'SubmitMisbehaviour',
      data
    )
    return promise.then((data) =>
      MsgSubmitMisbehaviourResponse.decode(new Reader(data))
    )
  }
}

interface Rpc {
  request(
    service: string,
    method: string,
    data: Uint8Array
  ): Promise<Uint8Array>
}

declare var self: any | undefined
declare var window: any | undefined
var globalThis: any = (() => {
  if (typeof globalThis !== 'undefined') return globalThis
  if (typeof self !== 'undefined') return self
  if (typeof window !== 'undefined') return window
  if (typeof global !== 'undefined') return global
  throw 'Unable to locate global object'
})()

const atob: (b64: string) => string =
  globalThis.atob ||
  ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary'))
function bytesFromBase64(b64: string): Uint8Array {
  const bin = atob(b64)
  const arr = new Uint8Array(bin.length)
  for (let i = 0; i < bin.length; ++i) {
    arr[i] = bin.charCodeAt(i)
  }
  return arr
}

const btoa: (bin: string) => string =
  globalThis.btoa ||
  ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64'))
function base64FromBytes(arr: Uint8Array): string {
  const bin: string[] = []
  for (let i = 0; i < arr.byteLength; ++i) {
    bin.push(String.fromCharCode(arr[i]))
  }
  return btoa(bin.join(''))
}

type Builtin = Date | Function | Uint8Array | string | number | undefined
export type DeepPartial<T> = T extends Builtin
  ? T
  : T extends Array<infer U>
  ? Array<DeepPartial<U>>
  : T extends ReadonlyArray<infer U>
  ? ReadonlyArray<DeepPartial<U>>
  : T extends {}
  ? { [K in keyof T]?: DeepPartial<T[K]> }
  : Partial<T>
